
package nccloud.web.arap.amortization.utils;

import nc.vo.arap.amortization.AggAmortizationVO;
import java.util.HashMap;
import java.util.Map;

import nc.vo.pubapp.pattern.model.entity.bill.AbstractBill;
import nc.vo.pubapp.pattern.model.entity.bill.IBill;
import nccloud.framework.web.ui.pattern.extbillcard.ExtBillCard;
import nccloud.framework.web.ui.pattern.extbillcard.ExtBillCardOperator;
import nccloud.framework.web.ui.pattern.grid.Grid;
import nccloud.framework.web.ui.pattern.grid.GridOperator;

/**
* @description 对即将返回前端的后台数据进行再处理
* @version ncc1.0
**/
public class ResultUtil {

        /**
        * 生成列表Grid
        *
        * @param bills
        *          待处理VO
        * @param size
        *          处理大小
        * @param pageId
        *          列表页面ID
        * @return
        */
        public static Grid convertBillsToGrid(IBill[] bills, String pageId) {
                if (bills == null || bills.length == 0)
                        return null;

                Object[] heads = new Object[bills.length];
                String[] allPks = new String[bills.length];
                for (int i = 0; i < bills.length; i++) {
                        heads[i] = bills[i].getParent();
                        allPks[i] = bills[i].getParent().getPrimaryKey();
                }
                GridOperator operator = new GridOperator(pageId);
                Grid grid = operator.toGrid(heads);
                grid.getModel().setAllpks(allPks);
                return grid;
        }

    public static Map<String, Object> getResult(AbstractBill[] bills, AbstractBill[] origBills) {
        Map<String, Object> retMap = new HashMap<>();
        if (bills != null && bills.length > 0) {
            nc.vo.arap.amortization.AggAmortizationVO ret = new AggAmortizationVO();
            if (origBills.length == 1) {
                ret = (AggAmortizationVO) bills[0];
                ExtBillCard billCard = null;
                ExtBillCardOperator operator = new ExtBillCardOperator("20060794_card");
                billCard = operator.toCard(ret);
                retMap.put("bills", billCard);
            } else {
                ret = null;
                int size = bills.length;
                Object[] heads = new Object[size];

                for (int i = 0; i < size; ++i) {
                    heads[i] = bills[i].getParent();
                }

                GridOperator operator = new GridOperator("20060794_list");
                Grid grid = operator.toGrid(heads);
                retMap.put("bills", grid);
            }
        }

        return retMap;
    }
}
